/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-09-01 09:15:51
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-09-26 15:58:34
 * @FilePath: \cxl-admin\src\pages\consumeManage\consume\statistics\index.ts
 */
import { BaseData, BaseMethod } from '@/utils/basc-data'
import * as tableConfig from './config.json'
import { consumeParams, consumeStatisticsList } from '@/apis/consume/consume'

export default class ConsumeStatisticsData extends BaseData implements BaseMethod {
    companyId = ''
    constructor() {
        super(tableConfig)
        this.getData()
    }

    getData = (arg?: any) => {
        const obj: consumeParams = {
            current: this.pageData.pagination.pageNo,
            size: this.pageData.pagination.pageSize
        }
        if (this.companyId) {
            obj.companyId = this.companyId
        }
        consumeStatisticsList(obj).then(res => {
            if (res.data.value === 200) {
                this.pageData.pagination.total = res.data.data.total
                this.pageData.table.data.length = 0

                res.data.data.records.forEach((item: any) => {
                    this.pageData.table.data.push(item)
                })
            }
        })
    }
    onSearch = (arg?: any) => {
        this.companyId = arg.companyId
        this.getData()
    }
    onReset = (arg?: any) => {
        this.pageData.pagination.pageNo = 1
        this.companyId = ''
        this.getData()
    }
    onPaginationChange = (arg?: any) => {
        this.pageData.pagination.pageNo = arg
        this.getData()
    }
    onPaginationSize = (arg?: any) => {
        this.pageData.pagination.pageNo = 1
        this.pageData.pagination.pageSize = arg
        this.getData()
    }
    onOperation = (arg?: any) => {}
}
